// const lineBg = "";
import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
export default {
	components: {
		baTreePicker
	},
	data() {
		return {
			// 用来装取排名信息
			rankList:[],
			// 当前选择的省市名称
			placeName:'全国',
			// 地区筛选数据
			filterPlaceData: [],
			loading:true,
			list4: [{
				name: '有限公司'
			}, {
				name: '湖南',
				badge: {
					isDot: true
				}
			},{
				name: '长沙新乐'
			}, {
				name: '机电设备',
				badge: {
					isDot: true
				}
			}],
			loadShow1: false,
			// 记录查询到的公司信息
			allCompany:[],

			// 分段器背景
			subheadBg: true,
			keyword: '点击查看更多企业',
			list: '才能招标，欢迎您！ 最新的招标信息，全面的企业详情，尽在才能招标。',
			classfiyList: [{
					name: '查企业',
					class: 'iconfont iconqiye'
				}, {
					name: '查业绩',
					class: 'iconfont iconyejifenxi'
				}, {
					name: '查人员',
					class: 'iconfont iconrenyuan'
				}, {
					name: '查资质',
					class: 'iconfont iconzizhi'
				}
				// ,
				// {
				// 	name: '查诚信',
				// 	class: 'iconfont iconchengxin'
				// }

			],
			subsectionList: [
				'新中标企业',
				'新中标项目经理'
			],

			scrollTop: 0,
			old: {
				scrollTop: 0
			},
			// 记录选择的是省份还是城市
			areaObj:{
				city:'',
				province:''
			},
			// 用户当前位置信息
			currentAddress:{},
			// 用来显示当前暂无相应信息
			
		}
	},
	onLoad() {
		let isLogin = uni.getStorageSync('isLogin') ;
		 
		if(isLogin == 1){

			this.filterPlaceData = uni.getStorageSync('filterPlaceData');
			//查询公司分类
			this.getCompanyType()
			
			this.hotList()
			// 获取用户当前位置信息
			let address=uni.getStorageSync('zb_setCurrentAddress')
			// this.currentAddress.companyCity=address.cityName
			
			if(address){
				this.currentAddress.provinceName=address.provinceName
			}
			
			this.placeName=address.provinceName
			if(this.areaObj.province){
				this.placeName=this.areaObj.province
				this.currentAddress.provinceName=null
			}
			if(this.areaObj.city){
				this.placeName==this.areaObj.city
				this.currentAddress.provinceName=null
			}
			
			// 查询所有公司信息
			this.findAllConmpany()
			
			this.filterPlaceData.unshift({
				name:'全国',
				value:'c'
			})
			//排行查询
			this.enterpriseRank('jianZhu')
			this.enterpriseRank('zaoJia')
			this.enterpriseRank('sheJi')
			this.enterpriseRank('jianLi')
		}else{
			//this.enterpriseRank('jianLi')
			this.$http.toLoginPage()
		}
		
		
		
	},
	methods: {
		//保存用户分类数据
		// 保存筛选的地域数据
		saveFilterCompanyTyp() {
			
		
			let companyTypeList = uni.getStorageSync('companyType');
			let data1 = []
			// 遍历公司类型
			if (companyTypeList) {
				companyTypeList.forEach((item1, index1) => {
					data1.push({
						"name": item1.name,
						"value": item1
					})
				})
				// 将转变后的公司类型
				uni.setStorageSync('filterCompanyType', data1);
			}
		
			// 删除已经缓存中的原有的地域和类型
			
			uni.removeStorageSync('companyType');
		
			// console.log("uni.getStorageSync('filterCompanyType')",uni.getStorageSync('filterCompanyType'))
		
		},
		// 获取用户分类数据
		getCompanyType(){
			let type = uni.getStorageSync('filterCompanyType');
			if ( !type) {
					// 查看公司分类数据
					let url1 = this.$baseApp.api.common.companyType
					this.$http.get(url1).then(res => {
						if (res.code == 200) {
							
							uni.setStorageSync('time2', Date.now());
							// 保存至缓存
							uni.setStorageSync('companyType', res.data);
							this.saveFilterCompanyTyp()
				
						} 
					})
				
				} else {
					//判断当前时间戳与之前的时间戳间隔时间是否大于等于一个月
					this.time = uni.getStorageSync('time2');
					let currentTime = Date.now()
					let overTime = (currentTime - this.time) / 1000
					if (overTime >= 2592000) {
						// 清除缓存再次调用接口
						
						uni.removeStorageSync('filterCompanyType')
						
						this.getCompanyType()
					} 
				}
		},
		// 热榜
		hotList(){
			let url = this.$baseApp.api.zhaobiao.hotWord;
			
			this.$http.get(url).then(res => {
				if (res.code == 200) {
					this.list4=[]
					
					res.data.company.forEach(item=>{
						this.list4.unshift({
							name:item.name,
							id:item.id
						})
					})
				} 
			})
		},
		
		// 查询企业排名
		enterpriseRank(type){
			let param={
				qualification:type,
			}
			if(this.currentAddress.provinceName){
				param.companyProvince=this.currentAddress.provinceName
			}
			// if(this.currentAddress.companyCity){
			// 	param.companyCity=this.currentAddress.companyCity
			// }
			if(this.areaObj.city){
				param.companyCity=this.areaObj.city
			}
			if(this.areaObj.province){
				param.companyProvince=this.areaObj.province
			}
			this.rankList=[]
			this.$app.request({
				url: this.$baseApp.api.check.findCompanyRankingList,
				data: param,
				method: 'GET',
				dataType: 'json',
				success: res => {
					if(res.data.content){
						res.data.content.forEach(item=>{
							if(item.companyName.length>14){
								item.companyName=item.companyName.slice(0,14)+'...'
							}
						})
								
						this.rankList.push(res.data.content)
					}else{
						this.rankList=null
					}
					
				},
				complete: res => {
				
				}
			});
		},
		
		
		//监听选择（ids为数组）
		selectChange(ids, names) {
			
			let size = ids.length
			this.placeName=names
			let str1
			this.areaObj={}
			this.currentAddress={}
			ids.forEach((item, index) => {
				if (item.indexOf('A') != -1) {
					this.areaObj.province= names
					
				} else if(item.indexOf('B') != -1){
					// 省
					this.areaObj.city=names
					
				}
			})
			
			this.findAllConmpany()
			this.rankList=[]
			this.enterpriseRank('jianZhu')
			this.enterpriseRank('zaoJia')
			this.enterpriseRank('sheJi')
			this.enterpriseRank('jianLi')
		},
		// 显示选择器
		showPicker() {
			this.$refs.treePicker._show();
		},
		tabsClick(item) {
			
			// 跳转至搜索页面进行搜索
			if(item.id&&item.id>4000){
				uni.navigateTo({
					url: `/pagesFind/detailenterprise/detailenterprise?companyCid=${item.id}`
				})
			}else{
				uni.navigateTo({
					url: `/pagesFind/findSearch/findSearch?name=${item.name}`
				});
			}
		},
		toSearch(){
			if(this.list4[0].id&&this.list4[0]>4000){
				uni.navigateTo({
					url: `/pagesFind/detailenterprise/detailenterprise?companyCid=${this.list4[0].id}`
				})
			}else{
				uni.navigateTo({
					url: `/pagesFind/findSearch/findSearch?name=${this.list4[0].name}`
				});
			}
			
			
		},
		
		// 信息提示
		showTip(data) {
			
			// 判断字符长度，长度大于7，用show，小于用alter
			if (data.length >= 7) {
				this.$refs.uToast.show({
					message: data,
					type: 'success'
				})
			} else {

				this.$alert(data);
			}

		},
		// 查询所有公司信息
		findAllConmpany() {
			let param={
					'page': 1,
					"pageSize": 10
				}
			if(this.currentAddress.provinceName){
				param.companyProvince=this.currentAddress.provinceName
			}
			if(this.currentAddress.companyCity){
				param.companyCity=this.currentAddress.companyCity
			}
			if(this.areaObj.city){
				param.companyCity=this.areaObj.city
			}
			if(this.areaObj.province){
				param.companyProvince=this.areaObj.province
			}
			
			this.loadShow1 = true
			
			this.$app.request({
				url: this.$baseApp.api.check.findNewBidding2,
				data: param,
				method: 'GET',
				dataType: 'json',
				success: res => {
					if (res.code == 200) 
						this.allCompany=res.data.content	
					
				},
				error:(res)=>{
					console.log("res",res)
				},
				complete: res => {
					this.loadShow1 = false
					
						this.loading=false
					
				}
			});
		},
		// 跳转至公司详情页面
		toDetailEnterprise(item) {

			// 将企业ID传值至详情页面
			uni.navigateTo({
				url: `/pagesFind/detailenterprise/detailenterprise?companyCid=${item.companyCid}`
			})
		},
		// 跳转至相应的查询页面
		checkEnterprise(index) {
			if (index == 0) {
				uni.navigateTo({
					url: `/pagesFind/checkEnterprise/checkEnterprise`
				})
			} else if (index == 1) {
				uni.navigateTo({
					url: `/pagesFind/checkAchievement/checkAchievement`
				})
			} else if (index == 2) {
				uni.navigateTo({
					url: `/pagesFind/checkPerson/checkPerson`
						// url: `/pagesFind/checkPerson/personKeyword`
				})
			} else if (index == 3) {

				uni.navigateTo({
					url: `/pagesFind/checkQualifications/checkQualifications`
				
				})
			} else {
				uni.navigateTo({
					url: `/pagesFind/checkSincerity/checkSincerity`
				})
			}
		},
		// 跳转至更多排行
		toMoreRank(index) {
			
			// 将index 传参至更多排行页面  将当前选择的位置信息传至下个页面
			let data
			//  param.companyProvince
			if(this.areaObj.province){
				data='&companyProvince='+this.areaObj.province
			}
			if(this.areaObj.city){
				data+='&companyCity='+this.areaObj.city
			}
			
			uni.navigateTo({
				url: `/pagesFind/moreRank/moreRank?order=${index}`+data
			})
		},
		// 跳转至  1 新中标企业 更多    2 项目经理 更多
		moreItem(num) {
			
			if (num == 1) {
				uni.navigateTo({
					url: './findSubPage/moreCompany/moreCompany'
				})
			} else {
				uni.navigateTo({
					url: './findSubPage/moreManager/moreManager'
				})
			}
		},
		// 跳转至搜索页面
		toFindSearch() {

			uni.navigateTo({
				url: '/pagesFind/findSearch/findSearch'
			})
		},
		// 分段器背景改变
		swichBg(index) {

			if (index == 1) {
				this.subheadBg = true
			} else {

				this.subheadBg = false

			}
		},
		upper: function(e) {
			console.log(e)
		},
		lower: function(e) {
			console.log(e)
		},
		scroll: function(e) {
			// console.log(e)
			this.old.scrollTop = e.detail.scrollTop
		},
		goTop: function(e) {
			// 解决view层不同步的问题
			this.scrollTop = this.old.scrollTop
			this.$nextTick(function() {
				this.scrollTop = 0
			});
			uni.showToast({
				icon: "none",
				title: "纵向滚动 scrollTop 值已被修改为 0"
			})
		}
	}

}
